#!/bin/bash
set -e

echo "=== 开始验证数据持久化 ==="

# 1. 使用REST API写入测试数据
echo "写入测试数据..."
curl -X POST -H "Content-Type: application/json" \
     -u ignite:ignite123 \
     -d '{"key": 1, "value": "test1"}' \
     http://localhost:10800/ignite?cmd=put&cacheName=defaultCache

# 2. 重启Ignite服务
echo "重启Ignite服务..."
docker-compose restart
sleep 10

# 3. 验证数据是否持久化
echo "验证数据持久化..."
curl -X GET -u ignite:ignite123 \
     http://localhost:10800/ignite?cmd=get&cacheName=defaultCache&key=1

# 4. 检查MySQL中的数据
echo "检查MySQL中的数据..."
mysql -h 192.168.3.79 -u root -proot -e "SELECT * FROM ignite.cache_data;"

echo "=== 验证完成 ===" 